﻿using ra2map_plus.data;
using ra2map_plus.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ra2map_plus
{
    partial class Form2 : Form
    {
        private readonly Form parent;
        private readonly Ra2MapPlusService service;
        public Form2(Form parent, Ra2MapPlusService service)
        {
            this.parent = parent;
            this.service = service;
            InitializeComponent();

            string location = this.service.Project.location;
            string projectName = new DirectoryInfo(location).Name;
            this.Text = $"{projectName} - Ra2MapPlus";
        }

        private void Form2_FormClosed(object sender, FormClosedEventArgs e)
        {
            parent.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool testMode = checkBox1.Checked;
            Console.WriteLine(testMode);
            // 合并输出
            service.MergeIni(testMode);
            service.Write();
            MessageBox.Show("合并输出成功！", "温馨提示");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 查看/修改项目配置文件
            Process p = new Process();
            p.StartInfo.UseShellExecute = true;

            string textEditor = GlobalDataHolder.AppConfig.textEditor;
            if (Path.IsPathRooted(textEditor))
            {
                FileInfo fileInfo = new FileInfo(textEditor);
                p.StartInfo.WorkingDirectory = fileInfo.Directory.FullName;
                p.StartInfo.FileName = fileInfo.Name;
            }
            else
            {
                p.StartInfo.FileName = textEditor;
            }

            p.StartInfo.Arguments = Path.Combine(service.Project.location, GlobalDataHolder.AppConfig.defaultProjectConfigFileName);

            p.Start();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("勾选测试模式时，会合并ini文件名包含有test的ini文件，否则不会合并", "温馨提示");
        }
    }
}
